import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;

import ru.ksu.ktk.diploma.sdi.analyzer.contingency.NominalData;
import ru.ksu.ktk.diploma.sdi.mapping.Triple;
import ru.ksu.ktk.diploma.sdi.mapping.learner.LearningExample;
import ru.ksu.ktk.diploma.sdi.mapping.learner.MappingLearner;
import ru.ksu.ktk.diploma.sdi.mapping.thesauri.DescriptorPair;

@ContextConfiguration(locations = {"classpath:META-INF/spring/mapping-beans.xml", "classpath:test-dao-beans.xml",
    "classpath:test-properties-beans.xml", "classpath:META-INF/spring/analyzer-beans.xml"})
public class MappingLearnerTestCase extends AbstractTestNGSpringContextTests {
    private static final String NOMINAL_DATA_PATH = "C://temp//emku//desc//emku-desc-name-technique.txt";
    @Autowired
    MappingLearner mappingLearner;

    @Test
    public void testLearn() throws NumberFormatException, IOException {
        List<LearningExample> learningExamples = new ArrayList<LearningExample>();
        List<NominalData> nominalDataList = FileUtil.readNominalData(NOMINAL_DATA_PATH);
        List<DescriptorPair> descriptorPairs = new ArrayList<DescriptorPair>();
        for (NominalData data : nominalDataList){
            String firstNominalValue = data.getFirstNominalValue();
            String secondNominalValue = data.getSecondNominalValue();
            int count = data.getCount();
            descriptorPairs.add(new DescriptorPair(firstNominalValue, secondNominalValue));
        }
        Triple firstTriple = new Triple("e24", "p2", "e55");
        Triple secondTriple = new Triple("e12", "p32", "e55");
        Triple predictedProperty = new Triple("e24", "p108", "e12");
        LearningExample learningExample = new LearningExample(firstTriple, secondTriple, predictedProperty);
        learningExample.setDescriptorPairs(descriptorPairs);
        learningExamples.add(learningExample);
        mappingLearner.learn(learningExamples);
    }
}
